package com.example.canvastest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 700 on 2018/7/30.
 */

public class DrawLineAndLines extends View{

    private Paint paint;
    private float[] linesoffset = new float[20];
    private int x = 200, y = 300;

    public DrawLineAndLines(Context context, AttributeSet attrs,
                        int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DrawLineAndLines(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawLineAndLines(Context context) {
        super(context);
    }

    private void initView(){
        for(int i = 0; i <20; i+=4){
            linesoffset[i] = 100;
            linesoffset[i+1] = 200+100*i/4;
            linesoffset[i+2] = 200;
            linesoffset[i+3] = 300+100*i/4;
        }
        paint = new Paint();
        paint.setColor(Color.BLUE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initView();
        canvas.drawLine(100,100,200,200, paint);
        canvas.drawLines(linesoffset,paint);
    }
}
